package org.chengsen.zhang;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.chengsen.zhang.util.FileUtil;
import org.springframework.util.Assert;

/**
 * Hello world!
 * 
 */
public class FileService {

	private static final String FILTER_PATTERN = "_";

	/**
	 * get file List from file
	 * 
	 * @param file
	 * @return
	 * @throws IOException
	 */
	public List<String> getFilteredContent(File file) throws IOException {

		Assert.notNull(file, "file should not be null");

		List<String> fileContents = FileUtil.readFile(file);

		return this.filter(fileContents, FILTER_PATTERN);
	}

	/**
	 * filter content
	 * 
	 * @param contentList
	 * @param pattern
	 * @return
	 */
	private List<String> filter(List<String> contentList, String pattern) {
		List<String> filteredList = new ArrayList<String>();
		for (String line : contentList) {
			if (!StringUtils.contains(line, pattern)) {
				filteredList.add(line);
			}
		}
		return filteredList;

	}
}
